import { User } from '@libs /db/Entitys/User.Enitty';
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOkResponse,
  ApiOperation,
  ApiTags,
} from '@nestjs/swagger';
import { JwtGuard } from 'src/guard/jwt.guard';
import { UsersService } from './users.service';

@ApiTags('用户/Users')
@Controller('users')
export class UsersController {
  constructor(private readonly UserService: UsersService) {}

  @Post('register')
  @ApiOkResponse({
    description: '成功',
  })
  @ApiOperation({ summary: '注册接口', description: '注册用户' })
  Register(@Body() body: User) {
    return this.UserService.Register(body);
  }

  @Post('login')
  @ApiOkResponse({
    description: '成功',
  })
  @ApiOperation({ summary: '登录接口', description: '用户登录' })
  Login(@Body() body: User) {
    return this.UserService.Login(body);
  }

  @ApiOperation({ summary: '获取用户接口', description: '获取用户信息' })
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  @Get('userinfo')
  getUserInfo(@Req() req) {
    return {
      code: 200,
      message: '获取信息成功',
      data: req.user,
    };
  }
}
